<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<chiptrack:checkLogon sourcePage="distributorSales.do"/>

<%@ page import="com.scalar.chiptrack.utils.ConfigManager,java.util.HashMap"%>

<chiptrack:checkLogon sourcePage="distributorSales.do"/>

<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>

<%
    String closeWindowAfterSave = ( String ) request.getAttribute( "closeWindowAfterSave" );
    String controlIndex         = ( String ) request.getAttribute( "controlIndex" );
    String totalQtyPulled       = ( String ) request.getAttribute( "totalQtyPulled" );
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML><HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type=text/css rel=stylesheet>
<script src="<%=chipTracContext%>/jsp/includes/scripts/functions.js"></script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></script>

<SCRIPT language="JavaScript">
<% if ( closeWindowAfterSave != null && closeWindowAfterSave.equalsIgnoreCase( "true" ) ) { %>
    window.opener.document.distributorSalesForm['lineItemList[<%=controlIndex%>].qtyShip'].value=<%=totalQtyPulled%>
    window.close();
<% } %>

    function submitLotDetails()
    {
        var form                    = document.distributorInventoryForm;
        var errors                  = "";

        /*if( form.requestedQty.value != form.totalQtyPulled.value )
        {
            errors = "<li> Requested Qty should be equal to Total Pulled Qty";
        }*/

        if( errors != "" )
        {
            var pa=document.getElementById("errors");
            pa.innerHTML = errors;
            return false;
        }
        else
        {
            form.totalQtyPulled.disabled = false;
            form.action='<%=chipTracContext%>/distributorInventory.do?action=save';
            form.submit();
            return true;
        }
    }

    function calculateTotalPulledQty()
    {
        var form            = document.distributorInventoryForm;
        var totalQtyPulled  = 0;

        if( typeof( form.hiddenLot ) != "undefined" )
        {
            var lotListSize     = form.hiddenLot.length;
            if( typeof( lotListSize ) == "undefined" )
            {
                totalQtyPulled = Number( form['inventoryList[0].qty_pulled'].value );
            }
            else
            {
                for ( k = 0; k < lotListSize; k++ )
                {
                    if ( (form['inventoryList[' + k + '].qty_pulled'].value).length > 0 )
                    {
                        totalQtyPulled += Number( form['inventoryList[' + k + '].qty_pulled'].value );
                    }
                }
            }
            form.totalQtyPulled.value = totalQtyPulled;
        }
    }


</SCRIPT>

</HEAD>

<BODY bgColor="#ffffff" leftMargin=0 topMargin=0 marginheight="0" marginwidth="0" onload="javascript:calculateTotalPulledQty();">

<SCRIPT language="JavaScript">
</SCRIPT>

<TABLE cellSpacing=0 cellPadding=0 width="100%" border="0">
	<TBODY>
	<TR>
		<td width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'></td>
		<td bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width="10"></td>
		<td valign="top" width="100%">
			<IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=450 border=0><BR>

			<html:form name="distributorInventoryForm" method="post" action="/distributorInventory" type="com.scalar.chiptrack.operations.distributor.forms.DistributorInventoryForm" >
			<center><span class="NArialW">Distributor Inventory</span></center><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20>
			<table border="0" width="100%" align=right >
				<tr>
					<td>
						<table border="0" width="100%" align=right>
						<tr><td colspan=6 class="NArialL" align="left"><font color="FF0000"><FONT id="errors"></FONT></font></td></tr>
						<tr><td colspan=6 id="svrErrors"><chiptrack:errors styleClass="NArialL"/></td></tr>
						<tr><td colspan=6 id="svrInfo"><chiptrack:info styleClass="NArialL"/></td></tr>
						<tr><td colspan=6><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=5></td></tr>
						<%
							HashMap errors = (HashMap)request.getAttribute( "error" );
							if( errors == null || errors.size() <= 0 )
							{
						%>
						<tr>
							<td width="20%"><font class="NArialL">Part Number</font></td>
							<td width="20%"><font class="NArialL">
								<bean:write name="distributorInventoryForm" property="partNumber"/>
                                <logic:present name="controlIndex">
                                    <input type="hidden" name="controlIndex" value='<%=request.getAttribute("controlIndex")%>' />
                                </logic:present>
                            </td>
							<td width="5%">&nbsp;</td>
							<td width="25%" class="NArialL">Distributor Name</td>
							<td width="30%" class="NArialL"><bean:write name="distributorInventoryForm" property="distributor"/></td>
							<td width="1%">&nbsp;</td>
						</tr>
						<%--<tr>
							<td width="20%"><font class="NArialL">Qty Requested</font></td>
							<td width="20%"><font class="NArialL">
								<bean:write name="distributorInventoryForm" property="requestedQty"/>
								<html:hidden name="distributorInventoryForm" property="requestedQty"/>
							</td>
							<td width="5%">&nbsp;</td>
							<td width="15%" class="NArialL">&nbsp;</td>
							<td width="30%">&nbsp;</td>
							<td width="10%">&nbsp;</td>
						</tr>--%>
						<tr><td colspan='6'><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>
						<tr>
							<td colspan='6' >
								<table border="0" width="70%" align="left">
								<tr><td colspan='5' align="left"><font class="NArialL">Inventory Details:</font></td></tr>
								<tr>
                                    <td width="20%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF">Sales Order#</font></td>
                                    <td width="10%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF">Unit Cost</font></td>
									<td width="20%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF">Lot No</font></td>
									<td width="20%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF">Date In</font></td>
									<td width="10%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF">Date Code</font></td>
									<td width="20%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF">Qty Available</font></td>
									<td width="20%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF">Qty Pulled</font></td>
								</tr>
								<nested:iterate id="lineitem" property="inventoryList" type="com.scalar.chiptrack.operations.distributor.DistributorInventory" indexId="lineItemIdx">
								<%
									int lineItemNoIdx = lineItemIdx.intValue() + 1;
								%>
								<tr>
                                    <td width="20%">
										<nested:text property="soNo" size="15" maxlength="50" styleClass="txfield" disabled="true"/>
									</td>
                                    <td width="10%">
										<nested:text property="unitCost" size="10" maxlength="50" styleClass="txfield" disabled="true"/>
									</td>
									<td width="20%">
										<nested:text property="lot_number" size="15" maxlength="50" styleClass="txfield" disabled="true"/>
									</td>
									<td width="20%">
										<nested:text property="date_in" size="15" maxlength="50" styleClass="txfield" disabled="true"/>
                                        <input type="hidden" name="hiddenLot">
                                    </td>
									<td width="10%"><nested:text property="dateCode" size="10" styleClass="txfield" disabled="true"/></td>
									<td width="20%"><nested:text property="qty_available" size="11" maxlength="10"  styleClass="txfield" disabled="true"/></td>
									<td width="20%"><nested:text property="qty_pulled" size="11" maxlength="10"  styleClass="txfield" onkeypress="javascript:allowInteger()" onkeyup="calculateTotalPulledQty()" /></td>
                                </tr>
								</nested:iterate>
                                <tr>
                                    <td width="20%">&nbsp;</td>
                                    <td width="10%">&nbsp;</td>
									<td width="20%">&nbsp;</td>
									<td width="20%">&nbsp;</td>
                                    <td width="40%" colspan="2" align="right" class="NArialL">Total Qty Pulled</td>
                                    <td width="20%"><input type="text" size='11' class="txfield"  disabled="true" name="totalQtyPulled" /></td>
                                </table>
							</td>
						</tr>
                        <tr><td colspan='6'><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>

                        <tr>
							<td colspan="6" align="center">
                                <img border="0" src="<%=chipTracContext%>/jsp/includes/images/save.gif" onclick="javascript:return submitLotDetails();" width="53" height="17" onmouseover="window.status='Click to Save';return true" onmouseout="window.status='';return true" title="Click to Save">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                <a href="javascript:document.distributorInventoryForm.reset();"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/reset.gif" width="53" height="17" onmouseover="window.status='Click to Reset';return true" onmouseout="window.status='';return true" title="Click here to Reset"></a>
							</td>
						</tr>
						<%
							}			
						%>
						</table>
					</td>
				</tr>
			</table>
			</html:form>
<!-- body ends here -->
		</td>
	</tr>
	</tbody>
</TABLE>

<!-- Footer starts here -->
<%@ include file="/jsp/includes/footer.jsp" %>

<!-- footer end here -->

</BODY>
</HTML>